package com.youlu.campus.web.community.controller;

import com.youlu.campus.base.base.PageQueryRequest;
import com.youlu.campus.service.ranking.entity.UserActivityPointRanking;
import com.youlu.campus.service.ranking.UserActivityPointDetailService;
import com.youlu.campus.service.ranking.UserActivityPointRankingService;
import com.youlu.campus.web.common.base.RequestContext;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * 领取活力值记录
 */
@RestController
public class UserActivityPointDetailController {

    @Autowired
    private UserActivityPointDetailService userActivityPointDetailService;

    @Autowired
    private UserActivityPointRankingService userActivityPointRankingService;

    /**
     * 用户领取活力值记录
     * @param request
     * @return
     */
    @PostMapping("/mini-app/receive-point/record")
     public QResult log(@RequestBody PageQueryRequest request){
         return QResult.success(userActivityPointDetailService.list(RequestContext.getUserId(),request));
     }

     @GetMapping("/mini-app/activity/my-point")
     public QResult getMyActivityPoint(@RequestParam("activityId") String activityId){
         UserActivityPointRanking userActivityPointRanking = userActivityPointRankingService.findByUserIdAndActivityId(RequestContext.getUserId(), activityId);
         if(Objects.isNull(userActivityPointRanking)){
             return QResult.success(0);
         }
         return QResult.success(userActivityPointRanking.getQuantity().intValue());
     }
}
